package  
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	/**
	 * ...
	 * @author Seven Gae
	 */
	public class Nave extends MovieClip
	{
		private var mousePressed:Boolean;
		private var desiredPosition: Number;
		
		public function Nave() 
		{
			this.scaleX = this.scaleY = 0.4;
			this.x = Main.Self.stage.stageWidth / 2;
			this.y = Main.Self.stage.stageHeight - this.height / 2 - 10;
			Main.Self.screen.addChild(this);
			Main.Self.stage.addEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown);
			Main.Self.stage.addEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
			
			desiredPosition = this.x;
		}
		
		public function update():void
		{
			
			if (mousePressed)
			{
				desiredPosition = Main.Self.mouseX;
			}
				
			if (this.x > Main.Self.stage.stageWidth - this.width / 2)
			{
				this.x = Main.Self.stage.stageWidth - this.width / 2;
			}
			else if (this.x < this.width / 2)
			{
				this.x = this.width / 2;
			}
				
			this.x += ((desiredPosition - this.x) / 5);
		}
		
		private function handleMouseDown(Evento:MouseEvent):void
		{
			mousePressed = true;
		}
		
		private function handleMouseUp(Evento:MouseEvent):void
		{
			mousePressed = false;
		}
		
		public function destroy():void
		{
			Main.Self.stage.removeEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown);
			Main.Self.stage.removeEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
			Main.Self.screen.removeChild(this);
		}
	}

}